package net.zhengxinyun.performance.service.app;

import net.zhengxinyun.performance.filter.CountryIndicatorsFilter;
import net.zhengxinyun.performance.mapper.Indicators.CountryIndicatorsEntityMapper;
import net.zhengxinyun.performance.mapper.Indicators.CountryScoreEntityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class AppHomeServiceImpl implements AppHomeService {
    @Autowired
    private CountryIndicatorsEntityMapper cityScoreMapper;

    @Override
    public HashMap<String, Object> CitySocure(String datetime) {

        CountryIndicatorsFilter filter = new CountryIndicatorsFilter();
        filter.setDateTime(datetime);
        filter.setAudit("1");
        List<CountryIndicatorsFilter> filters = cityScoreMapper.queryByTwoTable(filter);

        //得分 = 权重*得分率
        int weights =0;
        double rates=0.0;
        for (CountryIndicatorsFilter item : filters) {

            weights=item.getWeight()+weights;
            rates=item.getFinalScore()+rates;

        }
        double finalScore = weights * rates / 100;
        String rank ="-";

        HashMap<String,Object> map = new HashMap<>();
        map.put("finalScore",finalScore+"");
        map.put("rank",rank);
        return map;
    }
}
